
/**
 * 格式化数字
 * 
 * @param number
 *            传入值
 * @param len
 *            保留小数后几位
 * @param flag
 *            是否进行千分位分割
 * @returns
 */

function formatNumber(number, flag, len) {
	//强制转成string类型
	number =String(number);
	number = number.replace(/\,/g, "");
	// 判断传入的数字是否为空
	if (isNaN(number) || number == "" || number == null || number == "null")
		return "0";
	if (len == undefined || isNaN(len)) {
		len = 2;
	}
	//进行四舍五入
	number = Math.round(number * Math.pow(10, len)) / Math.pow(10, len);
	if (flag == undefined) {
		flag = false;
	}
	if (typeof flag != "boolean") {
		flag = false;
	}
	if (flag) {
		if (number < 0)
			return '-' + outputDollars(Math.floor(Math.abs(number) - 0) + '')
					+ outputCents(Math.abs(number) - 0,len);
		else
			return outputDollars(Math.floor(number - 0) + '')
					+ outputCents(number - 0,len);
	} else {
		return number;
	}
}
/**
 * 千分位符格式化
 * 
 * @param number
 * @returns
 */
function outputDollars(number) {
	if (number.length <= 3)
		return (number == '' ? '0' : number);
	else {
		var mod = number.length % 3;
		var output = (mod == 0 ? '' : (number.substring(0, mod)));
		for ( var i = 0; i < Math.floor(number.length / 3); i++) {
			if ((mod == 0) && (i == 0))
				output += number.substring(mod + 3 * i, mod + 3 * i + 3);
			else
				output += ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
		}
		return (output);
	}
}
/**
 * 填充小数
 * 
 * @param amount
 * @returns
 */
function outputCents(amount,len) {
	amount = Math.round(((amount) - Math.floor(amount)) * Math.pow(10, len));
	return (amount < 10 ? '.0' + amount : '.' + amount);
}

/**
 * 判断是否是数字
 * @param num
 */
function isNumber(num){
	if(num==null){
		return false;
	}
	//去掉千位符","
	num =num.replace(/\,/g, "");
	//去掉百分号
	num = num.replace(/\%/g,"");
	return  $.isNumeric(num);
}